package com.lwj.liwanjia.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.lwj.liwanjia.R;
import com.lwj.liwanjia.bean.DingBean01;
import com.lwj.liwanjia.config.OnItemClickListener;
import com.lwj.liwanjia.view.activity.work.shang_jia.ding_dan.DingDanXiangQingHomeActivity;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/11/9.
 */

public class SjIndentAdapter extends RecyclerView.Adapter<SjIndentAdapter.MyViewHolder> {

    private Context context;
    private List<DingBean01.DataBean.GoodsBean.CommodityBean> list;
    private LayoutInflater inflater;
    private OnItemClickListener listener;

    public void setListener(OnItemClickListener listener) {
        this.listener = listener;
    }

    public SjIndentAdapter(Context context, List<DingBean01.DataBean.GoodsBean.CommodityBean> list) {
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.my_indent_item, parent, false);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        DingBean01.DataBean.GoodsBean.CommodityBean commodityBean = list.get(position);
        Glide.with(context).load(commodityBean.getCommodityimage()).into(holder.ivShangpin);
        holder.tvShangpin.setText(commodityBean.getCommodityname());
        holder.tvJianjie.setText(commodityBean.getCommodityinfo());
        holder.tvPrice.setText("¥" + commodityBean.getCommodityprice());
        holder.tvNum.setText("*" + commodityBean.getCommodityNum());
        if(listener!=null){
            holder.rlIndent.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    listener.OnItemClick(v,position);
                }
            });
        }

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.iv_shangpin)
        ImageView ivShangpin;
        @BindView(R.id.tv_shangpin)
        TextView tvShangpin;
        @BindView(R.id.tv_jianjie)
        TextView tvJianjie;
        @BindView(R.id.tv_price)
        TextView tvPrice;
        @BindView(R.id.tv_num)
        TextView tvNum;
        @BindView(R.id.indent_item)
        RelativeLayout rlIndent;

        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
